package com.cc.nosql.controller;

import com.cc.nosql.po.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Bookcontroller {
    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    StringRedisTemplate StringRedisTemplate;

    @GetMapping("/test1")
    public void testl() {
        ValueOperations<String, String> ops1 = StringRedisTemplate.opsForValue();
        ops1.set("name", "三国演义");
        String name = ops1.get("name");
        System.out.println(name);

        ValueOperations ops2 = redisTemplate.opsForValue();
        Book b1 = new Book();
        b1.setId(1);
        b1.setName("红楼梦");
        b1.setAuthor("曹雪芹");
        ops2.set("b1", b1);
        Book book = (Book) ops2.get("b1");
        System.out.println(book);
    }

    @GetMapping("/test2")
    public void test2() {
        ValueOperations ops = redisTemplate.opsForValue();
        Book book = new Book();
        book.setName("水浒传");
        book.setAuthor("施耐庵");
        ops.set("bl", book);
        System.out.println(ops.get("bl"));
        ValueOperations<String, String> ops2 = StringRedisTemplate.opsForValue();
        ops2.set("kl", "vl");
        System.out.println(ops2.get("kl"));
    }
}